//
//  UIButton+Extension.swift
//  Rhythm_SinaWeibo
//
//  Created by Mr.Rhythm on 9/21/15.
//  Copyright © 2015 Mr.Rhythm. All rights reserved.
//

import UIKit

extension UIButton {
    convenience init(imageName: String,backImageName:String) {
        // 实例化按钮
        self.init()
        
        setImage(UIImage(named: imageName), forState: .Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: .Highlighted)
        
        // 自动调整大小
        sizeToFit()
    }
    
    convenience init(title: String, fontSize: CGFloat, color: UIColor, backImageName: String) {
        self.init()
        
        setTitle(title, forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
        setTitleColor(color, forState: UIControlState.Normal)
        
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
    }
}
